package cn.wolfcode.crm.domain;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
public class Customer {
    private Long id;
    private String name;
    private Integer age;
    private Integer gender;
    private String tel;
    private String qq;
    //职业
    private SystemDictionaryItem job;
    //来源
    private SystemDictionaryItem source;
    //销售员
    private Employee seller;
    //录入人
    private Employee inputUser;
    private Date inputTime;
    //状态
    private Integer status = STATUS_POTENTIAL;
    //定义常量为每个数字命名
    public static final int STATUS_POTENTIAL=0;
    public static final int STATUS_POOL=1;
    public static final int STATUS_FAILED=2;
    public static final int STATUS_NORMAL=3;
    public static final int STATUS_LOSE=4;

    public String getGenderName(){
       String GenderName = "";
       if(gender==0){
           GenderName = "女";
       }else{
           GenderName = "男";
       }
       return GenderName;
    }

    public String getStatusName(){
        String StatusName="";
        if(status==STATUS_POTENTIAL){
            StatusName="潜在客户";
        }else if(status==STATUS_POOL){
            StatusName="资源池客户";
        }else if(status==STATUS_FAILED){
            StatusName="失败客户";
        }else if(status==STATUS_NORMAL){
            StatusName="正常客户";
        }else{
            StatusName="流失客户";
        }
        return StatusName;
    }



    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("age",age);
        map.put("gender",gender);
        map.put("tel",tel);
        map.put("qq",qq);
        map.put("jobId",job.getId());
        map.put("sourceId",source.getId());
        map.put("sellerId",seller.getId());
        map.put("sellerName",seller.getName());

        ObjectMapper mapper = new ObjectMapper();
        try {
            String json = mapper.writeValueAsString(map);
            return json;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;

    }
}